package com.swift.authority.application.controller;

import com.swift.authority.common.constant.CommonEnum;
import com.swift.authority.common.response.ResponseResult;
import com.swift.authority.core.menu.response.MenuRes;
import com.swift.authority.service.menu.MenuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author Ldanniel
 * @description :
 * @date 2022/07/10 20:58
 * @since open jdk 1.8
 */
@RestController
@RequestMapping("menus")
public class MenuController {
    private final Logger logger = LoggerFactory.getLogger(MenuController.class);
    @Autowired
    private MenuService menuService;
    @PostMapping("/queryMenuInfo")
    public ResponseResult<Map<String, List<MenuRes>>> queryMenuInfo(){
        ResponseResult<Map<String, List<MenuRes>>> response = new ResponseResult<>(CommonEnum.SUCCESS);
        try{
            logger.info("获取按钮信息");
            Map<String, List<MenuRes>> menusMap = menuService.queryMenuInfo();
            response.setData(menusMap);
        }catch (Exception e){
            logger.error("获取按钮信息异常",e);
            response.setMessage(CommonEnum.FAILURE.getDescription());
            response.setStatus(CommonEnum.FAILURE.getCode());
        }
        return response;
    }

}
